<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>DLLSample.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - DLL example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">; This example is a skeleton to build easely a DLL using PureBasic
</font><font color="#3A3966">; The dll is created in the 'Compilers' directory, under the
</font><font color="#3A3966">; 'purebasic.dll' name. An associated '.lib' is generated to use
</font><font color="#3A3966">; with VisualC++.
</font><font color="#3A3966">;
</font><font color="#3A3966">;
</font><font color="#3A3966">; Rules to follow:
</font><font color="#3A3966">;   - Never write code outside a procedure, except for variables
</font><font color="#3A3966">;   or structure declaration.
</font><font color="#3A3966">;   
</font><font color="#3A3966">;   - DirectX Init routines must not be initialized in the the
</font><font color="#3A3966">;   AttachProcess() procedure
</font><font color="#3A3966">;   
</font><font color="#3A3966">;   - There is 4 procedures automatically called: AttachProcess(),
</font><font color="#3A3966">;   DetachProcess(), AttachThread() and DetachThread(). If you don't
</font><font color="#3A3966">;   need them, just remove them.
</font><font color="#3A3966">;
</font>
<font color="#924B72">#TESTDLL</font> = 0

<b><font color="#3A3966">CompilerIf</font></b> <font color="#924B72">#TESTDLL</font> = 0

  <b><font color="#3A3966">CompilerIf</font></b> <font color="#924B72">#PB_Compiler_OS</font> = <font color="#924B72">#PB_OS_Windows</font>

    <font color="#3A3966">; These 4 procedures are Windows specific
</font>    <font color="#3A3966">;
</font>
    <font color="#3A3966">; This procedure is called once, when the program loads the library
</font>    <font color="#3A3966">; for the first time. All init stuffs can be done here (but not DirectX init)
</font>    <font color="#3A3966">;
</font>    <b><font color="#3A3966">ProcedureDLL</font></b> <font color="#3A3966">AttachProcess</font>(Instance)
    <b><font color="#3A3966">EndProcedure</font></b>
  

    <font color="#3A3966">; Called when the program release (free) the DLL
</font>    <font color="#3A3966">;
</font>    <b><font color="#3A3966">ProcedureDLL</font></b> <font color="#3A3966">DetachProcess</font>(Instance)
    <b><font color="#3A3966">EndProcedure</font></b>
  

    <font color="#3A3966">; Both are called when a thread in a program call or release (free) the DLL
</font>    <font color="#3A3966">;
</font>    <b><font color="#3A3966">ProcedureDLL</font></b> <font color="#3A3966">AttachThread</font>(Instance)
    <b><font color="#3A3966">EndProcedure</font></b>
  
    <b><font color="#3A3966">ProcedureDLL</font></b> <font color="#3A3966">DetachThread</font>(Instance)
    <b><font color="#3A3966">EndProcedure</font></b>

  <b><font color="#3A3966">CompilerEndIf</font></b>

  <font color="#3A3966">; Real code start here..
</font>  <font color="#3A3966">;
</font>  <b><font color="#3A3966">ProcedureDLL</font></b> <font color="#3A3966">EasyRequester</font>(Message$)

<font color="#3A3966">    MessageRequester</font>("EasyRequester !", Message$)

  <b><font color="#3A3966">EndProcedure</font></b>

<b><font color="#3A3966">CompilerElse</font></b>

  <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenLibrary</font>(0, "PureBasic.dll") <b><font color="#3A3966">Or</font></b> <font color="#3A3966">OpenLibrary</font>(0, "PureBasic.so")
<font color="#3A3966">    CallFunction</font>(0, "EasyRequester", @"Test")
  <b><font color="#3A3966">EndIf</font></b>
    
<b><font color="#3A3966">CompilerEndIf</font></b>
</font></pre>
</body></html>
